package com.yitongmao.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebViewClient;

import com.google.gson.Gson;
import com.yitongmao.AppConstancts;
import com.yitongmao.bean.LoginHuancunBean;
import com.yitongmao.core.cache.ACache;
import com.yitongmao.util.SignUtil;
import com.yitongmao.util.X5WebView;
import com.yitongmao.yitmfruit.R;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.Random;

import butterknife.Bind;
import butterknife.ButterKnife;

public class RefundDetailsActivity extends AppCompatActivity {

    @Bind(R.id.mRedaihuitui)
    AutoLinearLayout mRedaihuitui;
    @Bind(R.id.mX5WebView)
    X5WebView mX5WebView;
    private LoginHuancunBean loginHuancunBean;
    private int loginId1;
    private String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        immerSion();
        setContentView(R.layout.activity_refund_details);
        ButterKnife.bind(this);
        setOnClick();
        initView();
    }

    private void initView() {
        Intent intent=getIntent();
        String order = intent.getStringExtra("order");
        mX5WebView.setWebViewClient(new WebViewClient());
        mX5WebView.setWebChromeClient(new WebChromeClient());
        Log.e("zzz",AppConstancts.Net.shoppingTuikuanUrl + "?code=" + order);
        //解析查找的缓存并判断
        Gson gson = new Gson();
        String loginId = ACache.get(RefundDetailsActivity.this).getAsString("loginId");
        if (loginId != null) {
            String timestamp = String.valueOf(System.currentTimeMillis());
            String nonce = String.valueOf(new Random().nextInt());
            loginHuancunBean = gson.fromJson(loginId, LoginHuancunBean.class);
            int id = loginHuancunBean.userInfo.id;
            loginId1 = loginHuancunBean.userInfo.loginId;
            userId = String.valueOf(id);
            mX5WebView.loadUrl(AppConstancts.Net.shoppingTuikuanUrl + "?id=" + order + "&loginId=" + loginId1 + "&signLogin=" + SignUtil.signLogin(nonce, timestamp) + "&timestamp=" + timestamp + "&nonce=" + nonce);
        }
    }
    private void setOnClick() {
        mRedaihuitui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RefundDetailsActivity.this.finish();
            }
        });
    }

    public void immerSion() {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.BLACK);
        }
    }
}
